package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.bo.LogiProjectBranchEditBo;
import com.piggy.logi.sys.bo.LogiProjectBranchQueryBo;
import com.piggy.logi.sys.service.ILogiProjectBranchService;
import com.piggy.logi.sys.vo.LogiProjectBranchExtVo;
import com.piggy.logi.sys.vo.LogiProjectBranchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 项目承运商管理Controller
 *
 * @author piggy
 * @date 2023-08-14
 */
@Api(value = "项目承运商管理控制器", tags = {"项目承运商管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/projbranch")
public class LogiProjectBranchController extends BaseController {

    private final ILogiProjectBranchService iLogiProjectBranchService;

    /**
     * 查询项目承运商管理列表
     */
    @ApiOperation("查询项目承运商管理列表")
    //@SaCheckPermission("sys:projbranch:list")
    @GetMapping("/list")
    public TableDataInfo<LogiProjectBranchExtVo> list(@Validated LogiProjectBranchQueryBo bo) {
        return iLogiProjectBranchService.queryPageList(bo);
    }

    /**
     * 导出项目承运商管理列表
     */
    @ApiOperation("导出项目承运商管理列表")
    //@SaCheckPermission("sys:projbranch:export")
    @LogiLog(title = "项目承运商管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiProjectBranchQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiProjectBranchExtVo> list = iLogiProjectBranchService.queryList(bo);
        ExcelUtil<LogiProjectBranchExtVo> util = new ExcelUtil<LogiProjectBranchExtVo>(LogiProjectBranchExtVo.class);
        util.exportExcel(response, list, "项目承运商管理");
    }

    /**
     * 获取项目承运商管理详细信息
     */
    @ApiOperation("获取项目承运商管理详细信息")
    //@SaCheckPermission("sys:projbranch:query")
    @GetMapping("/{id}")
    public R<LogiProjectBranchVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iLogiProjectBranchService.queryById(id));
    }

    /**
     * 新增项目承运商管理
     */
    @ApiOperation("新增项目承运商管理")
    //@SaCheckPermission("sys:projbranch:add")
    @LogiLog(title = "项目承运商管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Integer> add(@Validated @RequestBody LogiProjectBranchEditBo bo) {
        return R.ok(iLogiProjectBranchService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改项目承运商管理
     */
    @ApiOperation("修改项目承运商管理")
    //@SaCheckPermission("sys:projbranch:edit")
    @LogiLog(title = "项目承运商管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Integer> edit(@Validated @RequestBody LogiProjectBranchEditBo bo) {
        return R.ok(iLogiProjectBranchService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除项目承运商管理
     */
    @ApiOperation("删除项目承运商管理")
    //@SaCheckPermission("sys:projbranch:remove")
    @LogiLog(title = "项目承运商管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return R.ok(iLogiProjectBranchService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
